use "C:\Users\jkbrueck\Documents\STATA\Fuel 4\market_values_scrap.dta", clear

*creates interpolated values for non-bluebook years of 2016, 2018

gen retyr = .
replace retyr = 2015 if d2017 == 0 & d2019 == 0
replace retyr = 2017 if d2017 == 1
replace retyr = 2019 if d2019 == 1

keep type manuf_yr mkt_value capy range eff airbus age retyr

save "C:\Users\jkbrueck\Documents\STATA\Fuel 4\market_values_scrap_small.dta", replace

sort age type retyr

gen mkt_value_int = (mkt_value + mkt_value[_n + 1])/2 if type == type[_n + 1] & age == age[_n + 1]

drop if retyr == 2019

replace mkt_value_int = mkt_value if mkt_value_int == .

drop mkt_value
rename mkt_value_int mkt_value

replace retyr = 2016 if retyr == 2015
replace retyr = 2018 if retyr == 2017

replace age = age + 1

save "C:\Users\jkbrueck\Documents\STATA\Fuel 4\market_values_scrap_small_shift.dta", replace

append using "C:\Users\jkbrueck\Documents\STATA\Fuel 4\market_values_scrap_small.dta"

sort age type retyr 

save "C:\Users\jkbrueck\Documents\STATA\Fuel 4\market_values_scrap_small_append.dta",replace

